﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using Infragistics.Win.UltraWinCalcManager;
using Infragistics.Win.CalcEngine;
using System.Collections;
using System.Text.RegularExpressions;
using Infragistics.Excel;
using cfg = System.Configuration;
using GoldPrinter;

namespace BYManageInfoSystem
{
    public partial class Frm_CreditCardRegister : DockContent
    {
        private DGBY.BLL.CreditCardRegisterTab m_bllCreditCardRegisterTab = new DGBY.BLL.CreditCardRegisterTab();
        private DGBY.BLL.FactoryDataTab m_bllFactoryDataTab = new DGBY.BLL.FactoryDataTab();
        private DGBY.BLL.BYDepartTab m_bllBYDepartTab = new DGBY.BLL.BYDepartTab();
        private DGBY.BLL.BYCompanyTab m_bllBYCompanyTab = new DGBY.BLL.BYCompanyTab();
        private DGBY.BLL.InternationalTradeBankTab m_bllInternationalTradeBankTab = new DGBY.BLL.InternationalTradeBankTab();
        private DGBY.BLL.T_ACL_User m_bllT_ACL_User = new DGBY.BLL.T_ACL_User();
        private DGBY.BLL.BiZhiTab m_bllBiZhiTab = new DGBY.BLL.BiZhiTab();
        private DGBY.BLL.MDCountryTab m_bllMDCountryTab = new DGBY.BLL.MDCountryTab();
        DGBY.Model.CreditCardRegisterTab m_modelCopyCreditCardRegisterTab = new  DGBY.Model.CreditCardRegisterTab();
        private bool m_bInsertFlag = false;
        private int m_nDelIndex = -1;
        Dictionary<string, int> m_dicCardNo = new Dictionary<string, int>();
        private InsertType m_InsertType = new InsertType();
        protected string templetFilePath = cfg.ConfigurationSettings.AppSettings["TempletFilePath"];
        public class CustomMergedCellEvaluator : Infragistics.Win.UltraWinGrid.IMergedCellEvaluator
        {
            UltraGridColumn m_BaseColumn = null;
            public CustomMergedCellEvaluator(UltraGrid UltraGridTemp)
            {
                foreach (UltraGridColumn column2 in UltraGridTemp.DisplayLayout.Bands[0].Columns)
                {
                    string str = column2.Header.Caption;
                    if (str == "信用证号收款日")
                    {
                        m_BaseColumn = column2;
                        break;
                    }
                }
            }
            // 合并日期相同的单元格（无需时间精确相同）
            public bool ShouldCellsBeMerged(UltraGridRow row1, UltraGridRow row2, UltraGridColumn column)
            {
                try
                {
                    string str1 = (string)row1.GetCellValue(m_BaseColumn);
                    string str2 = (string)row2.GetCellValue(m_BaseColumn);
                    //string strTemp = str1.Substring(str1.Length - 1, 1);
                    //return str1 == str2 && strTemp != "0";
                    return str1 == str2;
                    //return true;

                }
                catch (System.Exception ex)
                {
                    //MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }


            }

        }
        public Frm_CreditCardRegister()
        {
            InitializeComponent();
        }

        private void Frm_CreditCardRegister_Load(object sender, EventArgs e)
        {
            ClassUltraGridCommonSet.InitUltraWinGridSetting(this.ultraGrid1);

            DataSet ds = m_bllCreditCardRegisterTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                StringBuilder str = new StringBuilder();

                int index = 0;
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    string strTemp = dr["信用证号"].ToString();
                    if (!string.IsNullOrEmpty(strTemp) && !m_dicCardNo.Keys.Contains(strTemp))
                    {
                        str.Append("," + strTemp);
                        m_dicCardNo.Add(strTemp, index++);
                    }
                }
                
                if (!string.IsNullOrEmpty(str.ToString()))
                {
                    string str2 = str.ToString().Substring(1);

                    this.textCreditCardNo.AutoCompleteCustomSource.AddRange(str2.Split(','));
                    this.textCreditCardNo.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
                    this.textCreditCardNo.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                }
            }
        }

        private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
        {
            if (this.checkBox1.Checked == true)
                ultraGrid1_InitializeRowFilter(e);
            else
                ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);

            ultraGrid1.DisplayLayout.Override.WrapHeaderText = Infragistics.Win.DefaultableBoolean.True;

            InitColumnWidth();
            InitComBox();

            e.Layout.Bands[0].Columns["交单次数"].Header.Appearance.ForeColor = Color.Blue;
            e.Layout.Bands[0].Columns["装柜日"].Header.Appearance.ForeColor = Color.Blue;
            e.Layout.Bands[0].Columns["开船日"].Header.Appearance.ForeColor = Color.Blue;
            e.Layout.Bands[0].Columns["交单日"].Header.Appearance.ForeColor = Color.Blue;
            e.Layout.Bands[0].Columns["开船到交单天数"].Header.Appearance.ForeColor = Color.Blue;
            e.Layout.Bands[0].Columns["交单金额"].Header.Appearance.ForeColor = Color.Blue;
            e.Layout.Bands[0].Columns["合同号"].Header.Appearance.ForeColor = Color.Blue;
            e.Layout.Bands[0].Columns["是否不符点"].Header.Appearance.ForeColor = Color.Blue;
            e.Layout.Bands[0].Columns["不符点备注"].Header.Appearance.ForeColor = Color.Blue;
            e.Layout.Bands[0].Columns["收款日"].Header.Appearance.ForeColor = Color.Blue;
            e.Layout.Bands[0].Columns["实收款"].Header.Appearance.ForeColor = Color.Blue;
            e.Layout.Bands[0].Columns["外汇牌价"].Header.Appearance.ForeColor = Color.Blue;
            e.Layout.Bands[0].Columns["国外扣费"].Header.Appearance.ForeColor = Color.Blue;
            e.Layout.Bands[0].Columns["国外扣费明细"].Header.Appearance.ForeColor = Color.Blue;
            e.Layout.Bands[0].Columns["国外扣费占比"].Header.Appearance.ForeColor = Color.Blue;
            e.Layout.Bands[0].Columns["交单到收款天数"].Header.Appearance.ForeColor = Color.Blue;

            e.Layout.Bands[0].Columns["应收快递费"].Header.Appearance.ForeColor = Color.Maroon;
            e.Layout.Bands[0].Columns["应收议付费"].Header.Appearance.ForeColor = Color.Maroon;
            e.Layout.Bands[0].Columns["应收通知费"].Header.Appearance.ForeColor = Color.Maroon;
            e.Layout.Bands[0].Columns["应收修改费"].Header.Appearance.ForeColor = Color.Maroon;
            e.Layout.Bands[0].Columns["应收电报费"].Header.Appearance.ForeColor = Color.Maroon;
            e.Layout.Bands[0].Columns["应收合计"].Header.Appearance.ForeColor = Color.Maroon;

            e.Layout.Bands[0].Columns["国内扣费占比"].Header.Appearance.ForeColor = Color.Maroon;
            e.Layout.Bands[0].Columns["扣费日"].Header.Appearance.ForeColor = Color.Maroon;
            e.Layout.Bands[0].Columns["应付快递费"].Header.Appearance.ForeColor = Color.Teal;
            e.Layout.Bands[0].Columns["快递费扣费日"].Header.Appearance.ForeColor = Color.Teal;
            e.Layout.Bands[0].Columns["应付议付费"].Header.Appearance.ForeColor = Color.Teal;
            e.Layout.Bands[0].Columns["议付费扣费日"].Header.Appearance.ForeColor = Color.Teal;
            e.Layout.Bands[0].Columns["应付通知费"].Header.Appearance.ForeColor = Color.Teal;
            e.Layout.Bands[0].Columns["通知费扣费日"].Header.Appearance.ForeColor = Color.Teal;
            e.Layout.Bands[0].Columns["应付电报费"].Header.Appearance.ForeColor = Color.Teal;
            e.Layout.Bands[0].Columns["电报费扣费日"].Header.Appearance.ForeColor = Color.Teal;
            e.Layout.Bands[0].Columns["应付合计"].Header.Appearance.ForeColor = Color.Teal;
            e.Layout.Bands[0].Columns["业务编号"].Header.Appearance.ForeColor = Color.Blue;
            e.Layout.Bands[0].Columns["发票号"].Header.Appearance.ForeColor = Color.Blue;

            foreach (UltraGridColumn column2 in ultraGrid1.DisplayLayout.Bands[0].Columns)
            {
                string str = column2.Header.Caption;
                if (str == "交单后是否完成收款"
                    || str == "部门信用证编号" || str == "开船到交单天数"
                    || str == "国外扣费占比" || str == "交单到收款天数"
                    || str == "应收合计" || str == "国内扣费占比"
                    || str == "扣费日" || str == "快递费扣费日"
                    || str == "议付费扣费日" || str == "通知费扣费日"
                    || str == "电报费扣费日" || str == "应收快递费" 
                    || str == "应收议付费" || str == "应收通知费" 
                    || str == "应收修改费" || str == "应收电报费"
                    || str == "应收合计" || str == "国内扣费占比"
                    || str == "应付合计")
                {
                    column2.CellAppearance.BackColor = Color.Coral;
                    column2.CellActivation = Activation.ActivateOnly;
                }
            }
        }

        private void InitComBox()
        {
            DataSet dsTemp = m_bllFactoryDataTab.GetList("");

            this.ultraDropDownFac.DataSource = dsTemp.Tables[0];
            this.ultraDropDownFac.DisplayMember = "工厂简称";
            this.ultraDropDownFac.ValueMember = "FactoryDataTabID";
            this.ultraDropDownFac.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownFac.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownFac.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownFac.DisplayLayout.Bands[0].Columns["工厂简称"].Hidden = false;

            dsTemp = m_bllInternationalTradeBankTab.GetList("");

            this.ultraDropDownInternational.DataSource = dsTemp.Tables[0];
            this.ultraDropDownInternational.DisplayMember = "名称";
            this.ultraDropDownInternational.ValueMember = "InternationalTradeBankTabID";
            this.ultraDropDownInternational.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownInternational.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownInternational.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownInternational.DisplayLayout.Bands[0].Columns["名称"].Hidden = false;

            dsTemp = m_bllBYCompanyTab.GetList("");

            this.ultraDropDownComp.DataSource = dsTemp.Tables[0];
            this.ultraDropDownComp.DisplayMember = "经营单位简称";
            this.ultraDropDownComp.ValueMember = "BYCompanyTabID";
            for (int i = 0; i < this.ultraDropDownComp.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownComp.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownComp.DisplayLayout.Bands[0].Columns["经营单位简称"].Hidden = false;

            dsTemp = m_bllT_ACL_User.GetList("Name != 'System1'");

            this.ultraDropDownPerson.DataSource = dsTemp.Tables[0];
            this.ultraDropDownPerson.DisplayMember = "用户名称";
            this.ultraDropDownPerson.ValueMember = "UserPasswordTabID";
            for (int i = 0; i < this.ultraDropDownPerson.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownPerson.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownPerson.DisplayLayout.Bands[0].Columns["用户名称"].Hidden = false;

            dsTemp = m_bllBiZhiTab.GetList("");

            this.ultraDropDownBiZhi.DataSource = dsTemp.Tables[0];
            this.ultraDropDownBiZhi.DisplayMember = "币制名称";
            this.ultraDropDownBiZhi.ValueMember = "BiZhiTabID";
            this.ultraDropDownBiZhi.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownBiZhi.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownBiZhi.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownBiZhi.DisplayLayout.Bands[0].Columns["币制名称"].Hidden = false;

            dsTemp = m_bllMDCountryTab.GetList("");
            this.ultraDropDownTargetCountry.DataSource = dsTemp.Tables[0];
            this.ultraDropDownTargetCountry.DisplayMember = "国家名称";
            this.ultraDropDownTargetCountry.ValueMember = "MDCountryTabID";
            this.ultraDropDownTargetCountry.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownTargetCountry.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownTargetCountry.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownTargetCountry.DisplayLayout.Bands[0].Columns["国家名称"].Hidden = false;
        }

        private void InitColumnWidth()
        {
            ultraGrid1.DisplayLayout.Bands[0].Columns["交单后是否完成收款"].Width = 45;
            ultraGrid1.DisplayLayout.Bands[0].Columns["通知行"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["工厂名称"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["部门"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["经营公司"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["跟单业务"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["部门信用证编号"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["信用证号"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["金额"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["币种"].Width = 45;
            ultraGrid1.DisplayLayout.Bands[0].Columns["目的国"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["修改次数"].Width = 40;
            ultraGrid1.DisplayLayout.Bands[0].Columns["开证行"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["开证人"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["开证日期"].Width = 95;
            ultraGrid1.DisplayLayout.Bands[0].Columns["最后船期"].Width = 95;
            ultraGrid1.DisplayLayout.Bands[0].Columns["最后押汇日"].Width = 95;
            ultraGrid1.DisplayLayout.Bands[0].Columns["议付银行"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["交单次数"].Width = 40;
            ultraGrid1.DisplayLayout.Bands[0].Columns["装柜日"].Width = 95;
            ultraGrid1.DisplayLayout.Bands[0].Columns["开船日"].Width = 95;
            ultraGrid1.DisplayLayout.Bands[0].Columns["交单日"].Width = 95;
            ultraGrid1.DisplayLayout.Bands[0].Columns["开船到交单天数"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["交单金额"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["合同号"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["是否不符点"].Width = 45;
            ultraGrid1.DisplayLayout.Bands[0].Columns["不符点备注"].Width = 100;
            ultraGrid1.DisplayLayout.Bands[0].Columns["收款日"].Width = 95;
            ultraGrid1.DisplayLayout.Bands[0].Columns["实收款"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["外汇牌价"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["国外扣费"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["国外扣费明细"].Width = 120;
            ultraGrid1.DisplayLayout.Bands[0].Columns["国外扣费占比"].Width = 45;
            ultraGrid1.DisplayLayout.Bands[0].Columns["交单到收款天数"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收快递费"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收议付费"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收通知费"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收修改费"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收电报费"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收合计"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["国内扣费占比"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["扣费日"].Width = 95;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应付议付费"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["快递费扣费日"].Width = 95;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应付议付费"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["议付费扣费日"].Width = 95;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应付通知费"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["通知费扣费日"].Width = 95;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应付电报费"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["电报费扣费日"].Width = 95;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应付合计"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["业务编号"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["发票号"].Width = 75;
        }

        private bool AddGoodsDetail()
        {
            try
            {
                DGBY.Model.CreditCardRegisterTab modelCreditCardRegisterTab = new DGBY.Model.CreditCardRegisterTab();
                modelCreditCardRegisterTab.IsCompleteRecvMoney = false;
                modelCreditCardRegisterTab.NotifyingBankID = 1;
                modelCreditCardRegisterTab.FactoryDataTabID = 297;
                modelCreditCardRegisterTab.BYCompanyTabID = 3;
                modelCreditCardRegisterTab.UserPasswordTabID = 49;
                modelCreditCardRegisterTab.DeptCreditCardRegisterTabNo = GetTodayMaxSerialNumber();
                modelCreditCardRegisterTab.CreditCardNo = "";
                modelCreditCardRegisterTab.JinE = 0;
                modelCreditCardRegisterTab.BiZhiTabID = 7;
                modelCreditCardRegisterTab.MDCountry = "";
                modelCreditCardRegisterTab.ModifyTime = 0;
                modelCreditCardRegisterTab.OpeningBank = "";
                modelCreditCardRegisterTab.OpeningBankPerson = "";
                modelCreditCardRegisterTab.OpeningBankDate = DateTime.Parse("1900-01-01");
                modelCreditCardRegisterTab.LastShipDate = DateTime.Parse("1900-01-01");
                modelCreditCardRegisterTab.LastDocumentaryDate = DateTime.Parse("1900-01-01");
                modelCreditCardRegisterTab.NegotiatingBankID = 1;
                modelCreditCardRegisterTab.DueTableTime = 0;
                modelCreditCardRegisterTab.InstalledCountersDate = DateTime.Parse("1900-01-01");
                modelCreditCardRegisterTab.SailDate = DateTime.Parse("1900-01-01");
                modelCreditCardRegisterTab.DueDate = DateTime.Parse("1900-01-01");
                modelCreditCardRegisterTab.DueJinE = 0;
                modelCreditCardRegisterTab.ContractCode = "";
                modelCreditCardRegisterTab.IsDiscrepancies = false;
                modelCreditCardRegisterTab.DiscrepanciesNode = "";
                modelCreditCardRegisterTab.RecvMoneyDate = DateTime.Parse("1900-01-01");
                modelCreditCardRegisterTab.RecvMoneyJinE = 0;
                modelCreditCardRegisterTab.ForeignExChange = 0;
                modelCreditCardRegisterTab.ForeignDebits = 0;
                modelCreditCardRegisterTab.ForeignDebitsDetail = "";
                modelCreditCardRegisterTab.DomesticDebitsRateDate = DateTime.Parse("1900-01-01");
                modelCreditCardRegisterTab.DHLFee = 0;
                modelCreditCardRegisterTab.DHLFeeDate = DateTime.Parse("1900-01-01");
                modelCreditCardRegisterTab.NegotiatingFee = 0;
                modelCreditCardRegisterTab.NegotiatingFeeDate = DateTime.Parse("1900-01-01");
                modelCreditCardRegisterTab.NotifyingFee = 0;
                modelCreditCardRegisterTab.NotifyingFeeDate = DateTime.Parse("1900-01-01");
                modelCreditCardRegisterTab.TelegraphFee = 0;
                modelCreditCardRegisterTab.TelegraphFeeDate = DateTime.Parse("1900-01-01");
                modelCreditCardRegisterTab.BillNo = "";
                modelCreditCardRegisterTab.InvoiceNo = "";

                int nID = m_bllCreditCardRegisterTab.Add(modelCreditCardRegisterTab);
                Frm_Main.Log2DB(this.Text, "增加", nID.ToString());

                ShowAllRecord("CreditCardRegisterTabID = '" + nID + "'");

                ultraGrid1.DisplayLayout.Bands[0].CardView = true;
                ultraGrid1.DisplayLayout.Bands[0].CardSettings.AllowLabelSizing = true;
                ultraGrid1.DisplayLayout.Bands[0].CardSettings.AllowSizing = true;
                ultraGrid1.DisplayLayout.Bands[0].CardSettings.Style = Infragistics.Win.UltraWinGrid.CardStyle.MergedLabels;
                ultraGrid1.DisplayLayout.Bands[0].CardSettings.ShowCaption = true;
                ultraGrid1.DisplayLayout.Bands[0].CardSettings.Width = 200;

                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }

        private bool AddGoodsCopyDetail()
        {
            try
            {
                m_modelCopyCreditCardRegisterTab.DueTableTime = 0;
                m_modelCopyCreditCardRegisterTab.InstalledCountersDate = DateTime.Parse("1900-01-01");
                m_modelCopyCreditCardRegisterTab.SailDate = DateTime.Parse("1900-01-01");
                m_modelCopyCreditCardRegisterTab.DueDate = DateTime.Parse("1900-01-01");
                m_modelCopyCreditCardRegisterTab.DueJinE = 0;
                m_modelCopyCreditCardRegisterTab.ContractCode = "";
                m_modelCopyCreditCardRegisterTab.IsDiscrepancies = false;
                m_modelCopyCreditCardRegisterTab.DiscrepanciesNode = "";
                m_modelCopyCreditCardRegisterTab.RecvMoneyDate = DateTime.Parse("1900-01-01");
                m_modelCopyCreditCardRegisterTab.RecvMoneyJinE = 0;
                m_modelCopyCreditCardRegisterTab.ForeignExChange = 0;
                m_modelCopyCreditCardRegisterTab.ForeignDebits = 0;
                m_modelCopyCreditCardRegisterTab.ForeignDebitsDetail = "";
                m_modelCopyCreditCardRegisterTab.DomesticDebitsRateDate = DateTime.Parse("1900-01-01");
                m_modelCopyCreditCardRegisterTab.DHLFee = 0;
                m_modelCopyCreditCardRegisterTab.DHLFeeDate = DateTime.Parse("1900-01-01");
                m_modelCopyCreditCardRegisterTab.NegotiatingFee = 0;
                m_modelCopyCreditCardRegisterTab.NegotiatingFeeDate = DateTime.Parse("1900-01-01");
                m_modelCopyCreditCardRegisterTab.NotifyingFee = 0;
                m_modelCopyCreditCardRegisterTab.NotifyingFeeDate = DateTime.Parse("1900-01-01");
                m_modelCopyCreditCardRegisterTab.TelegraphFee = 0;
                m_modelCopyCreditCardRegisterTab.TelegraphFeeDate = DateTime.Parse("1900-01-01");
                m_modelCopyCreditCardRegisterTab.BillNo = "";
                m_modelCopyCreditCardRegisterTab.InvoiceNo = "";

                int nID = m_bllCreditCardRegisterTab.Add(m_modelCopyCreditCardRegisterTab);
                Frm_Main.Log2DB(this.Text, "复制增加", nID.ToString());

                if (string.IsNullOrEmpty(m_modelCopyCreditCardRegisterTab.CreditCardNo))
                {
                    ShowAllRecord("CreditCardRegisterTabID = '" + nID.ToString() + "'");
                }
                else
                {
                    ShowAllRecord("CreditCardNo = '" + m_modelCopyCreditCardRegisterTab.CreditCardNo + "'");
                }

                /*
                ultraGrid1.DisplayLayout.Bands[0].CardView = true;
                ultraGrid1.DisplayLayout.Bands[0].CardSettings.AllowLabelSizing = true;
                ultraGrid1.DisplayLayout.Bands[0].CardSettings.AllowSizing = true;
                ultraGrid1.DisplayLayout.Bands[0].CardSettings.Style = Infragistics.Win.UltraWinGrid.CardStyle.MergedLabels;
                ultraGrid1.DisplayLayout.Bands[0].CardSettings.ShowCaption = true;
                ultraGrid1.DisplayLayout.Bands[0].CardSettings.Width = 200;
                */

                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }

        private String GetTodayMaxSerialNumber()
        {
            string strTodayMaxSerialNumber = DateTime.Now.ToString("yyyyMMdd");
            DataSet ds = m_bllCreditCardRegisterTab.GetTodayMaxSerialNumber();

            string strTemp = "";
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                strTemp = ds.Tables[0].Rows[0]["当前流水号"].ToString();

                if (strTemp != "")
                {
                    int nTemp = Convert.ToInt32(strTemp, 10) + 1;
                    strTemp = nTemp.ToString().PadLeft(3, '0'); ;
                }
                else
                {
                    strTemp = "001";
                }
            }
            else
            {
                strTemp = "001";
            }

            return strTodayMaxSerialNumber + strTemp;
        }

        public static void ultraGrid1_InitializeRowFilter(Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            //ultraGrid1.DisplayLayout.Override.RowSizing = RowSizing.AutoFree;
            //foreach (UltraGridColumn ugc in ultraGrid1.DisplayLayout.Bands[0].Columns)
            //    ugc.PerformAutoResize();
            // FILTER ROW FUNCTIONALITY RELATED ULTRAGRID SETTINGS
            //e.Layout.Override.RowFilterAction = RowFilterAction.DisableFilteredOutRows;
            // ----------------------------------------------------------------------------------
            // Enable the the filter row user interface by setting the FilterUIType to FilterRow.
            e.Layout.Override.FilterUIType = FilterUIType.FilterRow;
            //e.Layout.Override.RowFilterMode = RowFilterMode.AllRowsInBand;
            // FilterEvaluationTrigger specifies when UltraGrid applies the filter criteria typed 
            // into a filter row. Default is OnCellValueChange which will cause the UltraGrid to
            // re-filter the data as soon as the user modifies the value of a filter cell.
            e.Layout.Override.FilterEvaluationTrigger = FilterEvaluationTrigger.OnCellValueChange;
            //e.Layout.Override.RowFilterMode = RowFilterMode.AllRowsInBand;
            // By default the UltraGrid selects the type of the filter operand editor based on
            // the column's DataType. For DateTime and boolean columns it uses the column's editors.
            // For other column types it uses the Combo. You can explicitly specify the operand
            // editor style by setting the FilterOperandStyle on the override or the individual
            // columns.

            e.Layout.Override.FilterOperandStyle = FilterOperandStyle.DropDownList;

            // By default UltraGrid displays user interface for selecting the filter operator. 
            // You can set the FilterOperatorLocation to hide this user interface. This
            // property is available on column as well so it can be controlled on a per column
            // basis. Default is WithOperand. This property is exposed off the column as well.
            e.Layout.Override.FilterOperatorLocation = FilterOperatorLocation.WithOperand;

            // By default the UltraGrid uses StartsWith as the filter operator. You use
            // the FilterOperatorDefaultValue property to specify a different filter operator
            // to use. This is the default or the initial filter operator value of the cells
            // in filter row. If filter operator user interface is enabled (FilterOperatorLocation
            // is not set to None) then that ui will be initialized to the value of this
            // property. The user can then change the operator as he/she chooses via the operator
            // drop down.
            e.Layout.Override.FilterOperatorDefaultValue = FilterOperatorDefaultValue.StartsWith;

            // FilterOperatorDropDownItems property can be used to control the options provided
            // to the user for selecting the filter operator. By default UltraGrid bases 
            // what operator options to provide on the column's data type. This property is
            // avaibale on the column as well.
            //e.Layout.Override.FilterOperatorDropDownItems = FilterOperatorDropDownItems.All;

            // By default UltraGrid displays a clear button in each cell of the filter row
            // as well as in the row selector of the filter row. When the user clicks this
            // button the associated filter criteria is cleared. You can use the 
            // FilterClearButtonLocation property to control if and where the filter clear
            // buttons are displayed.
            e.Layout.Override.FilterClearButtonLocation = FilterClearButtonLocation.RowAndCell;

            // Appearance of the filter row can be controlled using the FilterRowAppearance proeprty.
            e.Layout.Override.FilterRowAppearance.BackColor = Color.LightYellow;

            // You can use the FilterRowPrompt to display a prompt in the filter row. By default
            // UltraGrid does not display any prompt in the filter row.
            e.Layout.Override.FilterRowPrompt = "Click here to filter data...";

            // You can use the FilterRowPromptAppearance to change the appearance of the prompt.
            // By default the prompt is transparent and uses the same fore color as the filter row.
            // You can make it non-transparent by setting the appearance' BackColorAlpha property 
            // or by setting the BackColor to a desired value.
            e.Layout.Override.FilterRowPromptAppearance.BackColorAlpha = Alpha.Opaque;

            // By default the prompt is spread across multiple cells if it's bigger than the
            // first cell. You can confine the prompt to a particular cell by setting the
            // SpecialRowPromptField property off the band to the key of a column.
            //e.Layout.Bands[0].SpecialRowPromptField = e.Layout.Bands[0].Columns[0].Key;

            // Display a separator between the filter row other rows. SpecialRowSeparator property 
            // can be used to display separators between various 'special' rows, including for the
            // filter row. This property is a flagged enum property so it can take multiple values.
            e.Layout.Override.SpecialRowSeparator = SpecialRowSeparator.FilterRow;

            // You can control the appearance of the separator using the SpecialRowSeparatorAppearance
            // property.
            e.Layout.Override.SpecialRowSeparatorAppearance.BackColor = Color.FromArgb(233, 242, 199);

            //   UltraGridBand band = e.Layout.Bands[0];
            //   band.ColumnFilters["原币金额"].FilterConditions.Clear();
            //   band.ColumnFilters["原币金额"].FilterConditions.Add(

            //FilterComparisionOperator.GreaterThan, 5);
            //   band.ColumnFilters["原币金额"].FilterConditions.Add(

            //FilterComparisionOperator.LessThan, 10);
            //   band.ColumnFilters["原币金额"].LogicalOperator = FilterLogicalOperator.And;
        }

        private void 增加一行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!m_bInsertFlag)
            {
                m_InsertType = InsertType.Common;
                UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
            }
        }

        private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
        {
            ultraGrid1.Rows[e.Row.Index].Cells[1].IgnoreRowColActivation = true;
            ultraGrid1.Rows[e.Row.Index].Cells[1].Activation = Activation.AllowEdit;
            ultraGrid1.Rows[e.Row.Index].Cells[1].Activate();
            ultraGrid1.PerformAction(UltraGridAction.EnterEditMode);

            m_bInsertFlag = true;

            if (m_InsertType == InsertType.Common)
                AddGoodsDetail();
            else if (m_InsertType == InsertType.MoreInsertCopy)
                AddGoodsCopyDetail();

            m_bInsertFlag = false;
        }

       

        private void buttonShowAll_Click(object sender, EventArgs e)
        {
            ShowAllRecord("");
        }

        private void ShowAllRecord(string strWhere)
        {
            DataSet ds = m_bllCreditCardRegisterTab.GetList(strWhere);
            ultraGrid1.DataSource = null;
            ultraGrid1.DataSource = ds.Tables[0];

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                ultraGrid1.DisplayLayout.Bands[0].Columns["CreditCardRegisterTabID"].Hidden = true;
                ultraGrid1.DisplayLayout.Bands[0].Columns["信用证号收款日"].Hidden = true;
                this.ultraGrid1.DisplayLayout.Bands[0].Columns["工厂名称"].ValueList = this.ultraDropDownFac;
                this.ultraGrid1.DisplayLayout.Bands[0].Columns["通知行"].ValueList = this.ultraDropDownInternational;
                this.ultraGrid1.DisplayLayout.Bands[0].Columns["议付银行"].ValueList = this.ultraDropDownInternational;
                this.ultraGrid1.DisplayLayout.Bands[0].Columns["经营公司"].ValueList = this.ultraDropDownComp;
                this.ultraGrid1.DisplayLayout.Bands[0].Columns["跟单业务"].ValueList = this.ultraDropDownPerson;
                this.ultraGrid1.DisplayLayout.Bands[0].Columns["币种"].ValueList = this.ultraDropDownBiZhi;

                Dictionary<string, int> dicFirstNotice = new Dictionary<string, int>();

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    UltraGridRow CurrentUGR = ultraGrid1.Rows[i];
                    if (null == CurrentUGR)
                        continue;

                    decimal deRate = CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[i]["国内扣费占比"].ToString())/10000, 2);
                    CurrentUGR.Cells["国内扣费占比"].Value = deRate.ToString() + "%";

                    deRate = CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[i]["国外扣费占比"].ToString())/10000, 2);
                    CurrentUGR.Cells["国外扣费占比"].Value = deRate.ToString() + "%";

                    CurrentUGR.Cells["应收快递费"].Value = CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[i]["应收快递费"].ToString()) / 100, 0).ToString();
                    CurrentUGR.Cells["应收议付费"].Value = CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[i]["应收议付费"].ToString()) / 100, 0).ToString();

                    string strCardNo = ds.Tables[0].Rows[i]["信用证号"].ToString();
                    if (!dicFirstNotice.Keys.Contains(strCardNo))
                    {
                        dicFirstNotice.Add(strCardNo, 0);
                        CurrentUGR.Cells["应收通知费"].Value = CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[i]["应收通知费"].ToString()) / 100, 0).ToString();
                        CurrentUGR.Cells["应收修改费"].Value = CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[i]["应收修改费"].ToString()) / 100, 0).ToString();
                    }
                    else
                    {
                        CurrentUGR.Cells["应收通知费"].Value = 0;
                        CurrentUGR.Cells["应收修改费"].Value = 0;
                    }  

                    CurrentUGR.Cells["应收电报费"].Value = CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[i]["应收电报费"].ToString()) / 100, 0).ToString();
                    CurrentUGR.Cells["应收合计"].Value = CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[i]["应收合计"].ToString()) / 100, 2).ToString();
                }
            }
        }

        private void SyncShouldRecvFee()
        {
            Dictionary<string, int> dicFirstNotice = new Dictionary<string, int>();
            foreach (UltraGridRow aRow in ultraGrid1.Rows)
            {
                string strCardNo = aRow.Cells["信用证号"].Value.ToString();
                if (!dicFirstNotice.Keys.Contains(strCardNo))
                {
                    dicFirstNotice.Add(strCardNo, 0);

                    int nCreditCardRegisterTabID = Convert.ToInt32(aRow.Cells["CreditCardRegisterTabID"].Value.ToString());
                    DataSet ds = m_bllCreditCardRegisterTab.GetList(" CreditCardRegisterTabID = '" + nCreditCardRegisterTabID + "'");


                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        decimal deRate = CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[0]["国内扣费占比"].ToString()) / 10000, 2);
                        aRow.Cells["国内扣费占比"].Value = deRate.ToString() + "%";

                        deRate = CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[0]["国外扣费占比"].ToString()) / 10000, 2);
                        aRow.Cells["国外扣费占比"].Value = deRate.ToString() + "%";

                        aRow.Cells["应收议付费"].Value = CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[0]["应收议付费"].ToString()) / 100, 0).ToString();
                        aRow.Cells["应收通知费"].Value = CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[0]["应收通知费"].ToString()) / 100, 0).ToString();
                        aRow.Cells["应收修改费"].Value = CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[0]["应收修改费"].ToString()) / 100, 0).ToString();
                        aRow.Cells["应收合计"].Value = CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[0]["应收合计"].ToString()) / 100, 2).ToString();
                    }
                }
                else
                {
                    aRow.Cells["国内扣费占比"].Value = "0%";
                    aRow.Cells["国外扣费占比"].Value = "0%";

                    aRow.Cells["应收议付费"].Value = 0; 
                    aRow.Cells["应收通知费"].Value = 0;
                    aRow.Cells["应收修改费"].Value = 0;
                }  
            }
        }

        private void 删除本行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("确实要删除该记录么!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (dr == DialogResult.Cancel)
            {
                return;
            }
            int nIndex = m_nDelIndex;
            if (m_nDelIndex >= 0)
            {
                if (ultraGrid1.ActiveRow != null)
                {
                    UltraGridRow CurrentUGR = ultraGrid1.Rows[nIndex];
                    ultraGrid1.ActiveRow.Delete(false);
                }
            }
            else
            {
                MessageBox.Show("请选中要删除的记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void ultraGrid1_AfterCellActivate(object sender, EventArgs e)
        {
            int iIndex = this.ultraGrid1.ActiveCell.Row.Index;
            if (iIndex < 0)
                return;
            m_nDelIndex = ultraGrid1.ActiveRow.Index;
        }

        private void ultraGrid1_BeforeRowsDeleted(object sender, BeforeRowsDeletedEventArgs e)
        {
            e.DisplayPromptMsg = false;
            if (!m_bInsertFlag)
            {
                int nSelectCreditCardRegisterTabID = Convert.ToInt32(ultraGrid1.ActiveRow.Cells[0].Value.ToString(), 10);
                DGBY.Model.CreditCardRegisterTab modelCreditCardRegisterTabOld
                    = m_bllCreditCardRegisterTab.GetModel(nSelectCreditCardRegisterTabID);

                if (modelCreditCardRegisterTabOld == null)
                {
                    MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (MessageBox.Show("确实要删除该条记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    try
                    {

                        m_bllCreditCardRegisterTab.Delete(nSelectCreditCardRegisterTabID);

                        SyncShouldRecvFee();
                        Frm_Main.Log2DB(this.Text, "删除", nSelectCreditCardRegisterTabID.ToString());


                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        e.Cancel = true;
                    }
                }
                else
                {
                    e.Cancel = true;
                }
            }
            else
            {
                MessageBox.Show("插入未完成，不能删除记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control)
            {
                if (!m_bInsertFlag)
                {
                    m_InsertType = InsertType.Common;
                    UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
                }
            }
            switch (e.KeyCode)
            {

                case Keys.Up:
                    {
                        UltraGridCell gridCell = this.ultraGrid1.ActiveCell;
                        if (null == gridCell)
                            return;

                        int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
                        int nIndex = ultraGrid1.ActiveRow.Index;
                        if (nIndex > 0)
                            nIndex--;
                        this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid1.PerformAction(UltraGridAction.AboveCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Down:
                    {
                        UltraGridCell gridCell = this.ultraGrid1.ActiveCell;
                        if (null == gridCell)
                            return;

                        int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
                        int nIndex = ultraGrid1.ActiveRow.Index;
                        if (nIndex < ultraGrid1.Rows.Count - 1)
                            nIndex++;
                        this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid1.PerformAction(UltraGridAction.BelowCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Right:
                    this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid1.PerformAction(UltraGridAction.NextCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
                case Keys.Left:
                    this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid1.PerformAction(UltraGridAction.PrevCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
            }
        }

        private void ultraGrid1_BeforeRowUpdate(object sender, CancelableRowEventArgs e)
        {
            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[e.Row.Index];

                if (m_bInsertFlag)
                {
                    ultraGrid1.Rows[e.Row.Index].Cells[2].Activation = Activation.ActivateOnly;
                    m_bInsertFlag = false;

                }
                else//修改
                {

                    ModifyGoodsDetail(e.Row.Index);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }

        private bool ModifyGoodsDetail(int nRowIndex)
        {
            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[nRowIndex];

                bool bModifyTime = false;
                bool bModifyShouldRecvFee = false;
                int nCreditCardRegisterTabID = Convert.ToInt32(CurrentUGR.Cells[0].Value.ToString(), 10);
                DGBY.Model.CreditCardRegisterTab modelCreditCardRegisterTabOld
                    = m_bllCreditCardRegisterTab.GetModel(nCreditCardRegisterTabID);

                if (modelCreditCardRegisterTabOld.NotifyingBankID != Convert.ToInt32(CurrentUGR.Cells["通知行"].Value.ToString()))
                    bModifyShouldRecvFee = true;

                modelCreditCardRegisterTabOld.NotifyingBankID = Convert.ToInt32(CurrentUGR.Cells["通知行"].Value.ToString());
                modelCreditCardRegisterTabOld.FactoryDataTabID = Convert.ToInt32(CurrentUGR.Cells["工厂名称"].Value.ToString());

                DataSet dsFac = m_bllFactoryDataTab.GetList("FactoryDataTabID = '" + modelCreditCardRegisterTabOld.FactoryDataTabID + "'");
                if (modelCreditCardRegisterTabOld.BYCompanyTabID == 3)
                {
                    if (dsFac.Tables.Count > 0 && dsFac.Tables[0].Rows.Count > 0)
                    {
                        modelCreditCardRegisterTabOld.BYCompanyTabID = Convert.ToInt32(dsFac.Tables[0].Rows[0]["BYCompanyTabID"].ToString());
                    }
                }
                else
                {
                    modelCreditCardRegisterTabOld.BYCompanyTabID = Convert.ToInt32(CurrentUGR.Cells["经营公司"].Value.ToString());
                }

                modelCreditCardRegisterTabOld.NegotiatingBankID = Convert.ToInt32(CurrentUGR.Cells["议付银行"].Value.ToString());
                modelCreditCardRegisterTabOld.UserPasswordTabID = Convert.ToInt32(CurrentUGR.Cells["跟单业务"].Value.ToString());
                modelCreditCardRegisterTabOld.CreditCardNo = CurrentUGR.Cells["信用证号"].Value.ToString();
                modelCreditCardRegisterTabOld.JinE = Convert.ToDecimal(CurrentUGR.Cells["金额"].Value.ToString());
                modelCreditCardRegisterTabOld.BiZhiTabID = Convert.ToInt32(CurrentUGR.Cells["币种"].Value.ToString());
                modelCreditCardRegisterTabOld.MDCountry = CurrentUGR.Cells["目的国"].Value.ToString();

                int nNewModifyTime = Convert.ToInt32(CurrentUGR.Cells["修改次数"].Value.ToString());
                if(nNewModifyTime != modelCreditCardRegisterTabOld.ModifyTime)
                {
                    modelCreditCardRegisterTabOld.ModifyTime = nNewModifyTime;
                    bModifyTime = true;
                }

                modelCreditCardRegisterTabOld.OpeningBank = CurrentUGR.Cells["开证行"].Value.ToString();
                modelCreditCardRegisterTabOld.OpeningBankPerson = CurrentUGR.Cells["开证人"].Value.ToString();
                modelCreditCardRegisterTabOld.OpeningBankDate = Convert.ToDateTime(CurrentUGR.Cells["开证日期"].Value.ToString());
                modelCreditCardRegisterTabOld.LastShipDate = Convert.ToDateTime(CurrentUGR.Cells["最后船期"].Value.ToString());
                modelCreditCardRegisterTabOld.LastDocumentaryDate = Convert.ToDateTime(CurrentUGR.Cells["最后押汇日"].Value.ToString());
                modelCreditCardRegisterTabOld.DueTableTime = Convert.ToInt32(CurrentUGR.Cells["交单次数"].Value.ToString());
                modelCreditCardRegisterTabOld.InstalledCountersDate = Convert.ToDateTime(CurrentUGR.Cells["装柜日"].Value.ToString());
                modelCreditCardRegisterTabOld.SailDate = Convert.ToDateTime(CurrentUGR.Cells["开船日"].Value.ToString());
                modelCreditCardRegisterTabOld.DueDate = Convert.ToDateTime(CurrentUGR.Cells["交单日"].Value.ToString());
                modelCreditCardRegisterTabOld.DueJinE = Convert.ToDecimal(CurrentUGR.Cells["交单金额"].Value.ToString());
                modelCreditCardRegisterTabOld.ContractCode = CurrentUGR.Cells["合同号"].Value.ToString();
                modelCreditCardRegisterTabOld.IsDiscrepancies = Convert.ToBoolean(CurrentUGR.Cells["是否不符点"].Value.ToString());
                modelCreditCardRegisterTabOld.DiscrepanciesNode = CurrentUGR.Cells["不符点备注"].Value.ToString();
                modelCreditCardRegisterTabOld.RecvMoneyDate = Convert.ToDateTime(CurrentUGR.Cells["收款日"].Value.ToString());

                modelCreditCardRegisterTabOld.RecvMoneyJinE = Convert.ToDecimal(CurrentUGR.Cells["实收款"].Value.ToString());
                if (modelCreditCardRegisterTabOld.RecvMoneyJinE > 0)
                {
                    modelCreditCardRegisterTabOld.IsCompleteRecvMoney = true;
                    modelCreditCardRegisterTabOld.DomesticDebitsRateDate = System.DateTime.Now.Date;
                }
                else
                {
                    modelCreditCardRegisterTabOld.IsCompleteRecvMoney = false;
                }

                if (modelCreditCardRegisterTabOld.ForeignExChange != Convert.ToDecimal(CurrentUGR.Cells["外汇牌价"].Value.ToString()))
                    bModifyShouldRecvFee = true;

                modelCreditCardRegisterTabOld.ForeignExChange = Convert.ToDecimal(CurrentUGR.Cells["外汇牌价"].Value.ToString());

                if (modelCreditCardRegisterTabOld.ForeignDebits != Convert.ToDecimal(CurrentUGR.Cells["国外扣费"].Value.ToString()))
                    bModifyShouldRecvFee = true;

                modelCreditCardRegisterTabOld.ForeignDebits = Convert.ToDecimal(CurrentUGR.Cells["国外扣费"].Value.ToString());
                modelCreditCardRegisterTabOld.ForeignDebitsDetail = CurrentUGR.Cells["国外扣费明细"].Value.ToString();

                if (modelCreditCardRegisterTabOld.DHLFee != Convert.ToDecimal(CurrentUGR.Cells["应付快递费"].Value.ToString()))
                    bModifyShouldRecvFee = true;

                modelCreditCardRegisterTabOld.DHLFee = Convert.ToDecimal(CurrentUGR.Cells["应付快递费"].Value.ToString());
                if(modelCreditCardRegisterTabOld.DHLFee > 0)
                {
                    modelCreditCardRegisterTabOld.DHLFeeDate =  System.DateTime.Now.Date;;
                }

                if (modelCreditCardRegisterTabOld.NegotiatingFee != Convert.ToDecimal(CurrentUGR.Cells["应付议付费"].Value.ToString()))
                    bModifyShouldRecvFee = true;

                modelCreditCardRegisterTabOld.NegotiatingFee = Convert.ToDecimal(CurrentUGR.Cells["应付议付费"].Value.ToString());
                if(modelCreditCardRegisterTabOld.NegotiatingFee > 0)
                {
                    modelCreditCardRegisterTabOld.NegotiatingFeeDate =  System.DateTime.Now.Date;;
                }

                if(modelCreditCardRegisterTabOld.NotifyingFee == 0 && Convert.ToDecimal(CurrentUGR.Cells["应付通知费"].Value.ToString()) > 0)
                {
                    modelCreditCardRegisterTabOld.NotifyingFee = Convert.ToDecimal(CurrentUGR.Cells["应付通知费"].Value.ToString());
                    modelCreditCardRegisterTabOld.NotifyingFeeDate =  System.DateTime.Now.Date;

                    bModifyShouldRecvFee = true;
                }

                if(modelCreditCardRegisterTabOld.TelegraphFee != Convert.ToDecimal(CurrentUGR.Cells["应付电报费"].Value.ToString()))
                    bModifyShouldRecvFee = true;

                modelCreditCardRegisterTabOld.TelegraphFee = Convert.ToDecimal(CurrentUGR.Cells["应付电报费"].Value.ToString());
                if(modelCreditCardRegisterTabOld.TelegraphFee > 0)
                {
                    modelCreditCardRegisterTabOld.TelegraphFeeDate =  System.DateTime.Now.Date;;
                }

                modelCreditCardRegisterTabOld.BillNo = CurrentUGR.Cells["业务编号"].Value.ToString();
                modelCreditCardRegisterTabOld.InvoiceNo = CurrentUGR.Cells["发票号"].Value.ToString();
           
                m_bllCreditCardRegisterTab.Update(modelCreditCardRegisterTabOld);
                Frm_Main.Log2DB(this.Text, "修改", nCreditCardRegisterTabID.ToString());

                CurrentUGR.Cells["交单后是否完成收款"].Value = modelCreditCardRegisterTabOld.IsCompleteRecvMoney;
                CurrentUGR.Cells["经营公司"].Value = modelCreditCardRegisterTabOld.BYCompanyTabID;

                if (nNewModifyTime > 0)
                {
                    CurrentUGR.Cells["应收修改费"].Value = 100;
                    bModifyShouldRecvFee = true;
                }
                else
                    CurrentUGR.Cells["应收修改费"].Value = 0;

                if (modelCreditCardRegisterTabOld.DueDate.Value.Year == 1900 || modelCreditCardRegisterTabOld.SailDate.Value.Year == 1900)
                {
                    CurrentUGR.Cells["开船到交单天数"].Value = 0;
                }
                else
                {
                    TimeSpan ts = modelCreditCardRegisterTabOld.DueDate.Value.Date - modelCreditCardRegisterTabOld.SailDate.Value.Date;
                    CurrentUGR.Cells["开船到交单天数"].Value = ts.Days;
                }

                if (modelCreditCardRegisterTabOld.RecvMoneyDate.Value.Year == 1900 || modelCreditCardRegisterTabOld.DueDate.Value.Year == 1900)
                {
                    CurrentUGR.Cells["交单到收款天数"].Value = 0;
                }
                else
                {
                    TimeSpan ts = modelCreditCardRegisterTabOld.RecvMoneyDate.Value.Date - modelCreditCardRegisterTabOld.DueDate.Value.Date;
                    CurrentUGR.Cells["交单到收款天数"].Value = ts.Days;
                }

                if (dsFac.Tables.Count > 0 && dsFac.Tables[0].Rows.Count > 0)
                {
                    CurrentUGR.Cells["部门"].Value = dsFac.Tables[0].Rows[0]["所属部门"].ToString();
                }

                CurrentUGR.Cells["应收快递费"].Value = CommonCompute.ChinaRound(modelCreditCardRegisterTabOld.DHLFee, 0);
                decimal dNegotiatingFee =  (modelCreditCardRegisterTabOld.DueJinE * modelCreditCardRegisterTabOld.ForeignExChange) * (decimal)0.00125;

                if (dNegotiatingFee > 300)
                    CurrentUGR.Cells["应收议付费"].Value = CommonCompute.ChinaRound(dNegotiatingFee, 0).ToString();
                else
                    CurrentUGR.Cells["应收议付费"].Value = 300;

                /*
                CurrentUGR.Cells["应付通知费"].Value = modelCreditCardRegisterTabOld.NotifyingFee;
                DGBY.Model.InternationalTradeBankTab modelInternationalTradeBankTab = m_bllInternationalTradeBankTab.GetModel(modelCreditCardRegisterTabOld.NotifyingBankID);
                if (modelInternationalTradeBankTab == null)
                    CurrentUGR.Cells["应收通知费"].Value = 0;
                else
                {
                    if (modelInternationalTradeBankTab.IsSpecialBank)
                    {
                        CurrentUGR.Cells["应收通知费"].Value = CommonCompute.ChinaRound(Convert.ToDecimal(CurrentUGR.Cells["应付通知费"].Value), 0).ToString();
                    }
                    else
                    {
                        CurrentUGR.Cells["应收通知费"].Value = 200;
                    }
                }
                */
               
                CurrentUGR.Cells["应收电报费"].Value = CommonCompute.ChinaRound(Convert.ToDecimal(CurrentUGR.Cells["应付电报费"].Value) * 2, 0).ToString();
                CurrentUGR.Cells["应收合计"].Value = CommonCompute.ChinaRound(Convert.ToDecimal(CurrentUGR.Cells["应收快递费"].Value.ToString()) + Convert.ToDecimal(CurrentUGR.Cells["应收议付费"].Value.ToString()) + Convert.ToDecimal(CurrentUGR.Cells["应收通知费"].Value.ToString()) + Convert.ToDecimal(CurrentUGR.Cells["应收修改费"].Value.ToString()) + Convert.ToDecimal(CurrentUGR.Cells["应收电报费"].Value.ToString()), 0).ToString();
               
                CurrentUGR.Cells["扣费日"].Value = Convert.ToDateTime(modelCreditCardRegisterTabOld.DomesticDebitsRateDate.ToString());
                CurrentUGR.Cells["快递费扣费日"].Value = Convert.ToDateTime(modelCreditCardRegisterTabOld.DHLFeeDate.ToString());
                CurrentUGR.Cells["议付费扣费日"].Value = Convert.ToDateTime(modelCreditCardRegisterTabOld.NegotiatingFeeDate.ToString());
                CurrentUGR.Cells["通知费扣费日"].Value = Convert.ToDateTime(modelCreditCardRegisterTabOld.NotifyingFeeDate.ToString());
                CurrentUGR.Cells["电报费扣费日"].Value = Convert.ToDateTime(modelCreditCardRegisterTabOld.TelegraphFeeDate.ToString());

                if (bModifyTime)
                    SyncCreditCardModifyTime(modelCreditCardRegisterTabOld.CreditCardNo, nNewModifyTime, nRowIndex);

                if (bModifyShouldRecvFee || bModifyTime)
                    SyncShouldRecvFee();           

                string strCardNo = modelCreditCardRegisterTabOld.CreditCardNo;
                if (!string.IsNullOrEmpty(strCardNo) && !m_dicCardNo.Keys.Contains(strCardNo))
                {
                    m_dicCardNo.Add(strCardNo, m_dicCardNo.Count);
                    this.textCreditCardNo.AutoCompleteCustomSource.Add(strCardNo);
                }

                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }

        private void SyncCreditCardModifyTime(string strCreditCardNo, int nModifyTime, int nExceptRow)
        {
            m_bllCreditCardRegisterTab.SyncCreditCardByModifyTime(strCreditCardNo, nModifyTime);
            for (int i = 0; i < this.ultraGrid1.Rows.Count; i++)
            {
                if (i == nExceptRow)
                    continue;

                UltraGridRow CurrentUGR = ultraGrid1.Rows[i];
                if (strCreditCardNo == CurrentUGR.Cells["信用证号"].Value.ToString())
                {
                    CurrentUGR.Cells["修改次数"].Value = nModifyTime;
                    CurrentUGR.Cells["应收修改费"].Value = nModifyTime * 100;
                }
            }
        }

        private void ultraGrid1_DoubleClickCell(object sender, DoubleClickCellEventArgs e)
        {
            string strTColumn = this.ultraGrid1.ActiveCell.Column.Header.Caption;
            if (strTColumn == "通知行" || strTColumn == "工厂名称" || strTColumn == "议付银行" || strTColumn == "经营公司"
               || strTColumn == "跟单业务" || strTColumn == "币种" || strTColumn == "目的国" || strTColumn == "开证日期"
               || strTColumn == "最后船期" || strTColumn == "最后押汇日" || strTColumn == "装柜日" || strTColumn == "开船日"
               || strTColumn == "交单日" || strTColumn == "收款日" || strTColumn == "扣费日" || strTColumn == "快递费扣费日"
               || strTColumn == "议付费扣费日" || strTColumn == "通知费扣费日" || strTColumn == "电报费扣费日")
            {
               return;
            }

            int iIndex = this.ultraGrid1.ActiveCell.Row.Index;
            if (iIndex < 0)
                return;

            int nSelectCreditCardRegisterTabID = Convert.ToInt32(ultraGrid1.ActiveRow.Cells[0].Value.ToString(), 10);
            ShowAllRecord("CreditCardRegisterTabID = '" + nSelectCreditCardRegisterTabID + "'");

            ultraGrid1.DisplayLayout.Bands[0].CardView = true;
            ultraGrid1.DisplayLayout.Bands[0].CardSettings.AllowLabelSizing = true;
            ultraGrid1.DisplayLayout.Bands[0].CardSettings.AllowSizing = true;
            ultraGrid1.DisplayLayout.Bands[0].CardSettings.Style = Infragistics.Win.UltraWinGrid.CardStyle.MergedLabels;
            ultraGrid1.DisplayLayout.Bands[0].CardSettings.ShowCaption = true;
            ultraGrid1.DisplayLayout.Bands[0].CardSettings.Width = 200;
        }

        private void textCreditCardNo_TextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.textCreditCardNo.Text))
            {
                ShowAllRecord("CreditCardNo = '" + this.textCreditCardNo.Text + "'");
            }
        }

        private void 复制增加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!m_bInsertFlag)
            {
                if (m_nDelIndex < 0)
                {
                    MessageBox.Show("请选择一行记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                UltraGridRow CurrentUGRFrom;
                CurrentUGRFrom = ultraGrid1.Rows[m_nDelIndex];

                if (null == CurrentUGRFrom)
                    return;

                int nSelTabID = Convert.ToInt32(CurrentUGRFrom.Cells[0].Value.ToString(), 10);
                m_modelCopyCreditCardRegisterTab = m_bllCreditCardRegisterTab.GetModel(nSelTabID);

                m_InsertType = InsertType.MoreInsertCopy;
                UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (m_nDelIndex < 0)
            {
                MessageBox.Show("请选择一行！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            DataTable dtNew = new DataTable();
            MakeFeeColumn(dtNew);

            decimal dDueTableFee = 0; 
            decimal dForeignlFee = 0;
            string strContractNo = FillDataTableFeeNew(dtNew, ref dDueTableFee, ref dForeignlFee);

            if (dtNew != null)
            {
                if (dtNew.Rows.Count > 0)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Excel文件(*.xls)|*.xls";
                    string outFile = "";
                   
                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        outFile = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }

                    string templetFile = templetFilePath + "信用证实收费用明细表.xlt";
                    

                    UltraGridRow CurrentUGR;
                    CurrentUGR = ultraGrid1.Rows[m_nDelIndex];

                    if (CurrentUGR == null)
                        return;

                    ExcelBase eB = new ExcelBase(templetFile, outFile);

                    try
                    {
                        decimal dJDValue = dDueTableFee - dForeignlFee;
                        eB.CreditCardRegister_DataTableToExcel(dtNew, 20, 14, 3, "页", 2
                            ,"客户：" + CurrentUGR.Cells["工厂名称"].Text.ToString()
                            , CurrentUGR.Cells["跟单业务"].Text.ToString()
                            , CurrentUGR.Cells["议付银行"].Text.ToString() + "业务编号:" + CurrentUGR.Cells["业务编号"].Value.ToString()
                            , "信用证：" + CurrentUGR.Cells["信用证号"].Value.ToString()
                            , "发票号:" + CurrentUGR.Cells["发票号"].Value.ToString()
                            , "合同号：" + strContractNo
                            , "交单金额:USD：" + dDueTableFee.ToString() + "-" + dForeignlFee.ToString() + "=" + dJDValue.ToString()
                            , "(到帐日:" + CurrentUGR.Cells["收款日"].Text.ToString() + ",汇率:" + CurrentUGR.Cells["外汇牌价"].Value.ToString() + ")"
                            , @"收费项目（" + CurrentUGR.Cells["快递费扣费日"].Text.ToString() + "):");
                    }
                    catch (System.Exception ex)
                    {

                    }

                    eB.Close();
             
                 
                }
            }
        }

        public void MakeFeeColumn(DataTable dt)
        {
            dt.Columns.Add("序号", System.Type.GetType("System.String"));
            dt.Columns.Add("项目", System.Type.GetType("System.String"));
            dt.Columns.Add("金额（RMB）", System.Type.GetType("System.String"));
            dt.Columns.Add("备注", System.Type.GetType("System.String"));
        }

        public string FillDataTableFeeNew(DataTable dtNew, ref decimal dDueTableFee, ref decimal dForeignlFee)
        {
            StringBuilder strContractNo = new StringBuilder();

            UltraGridRow CurrentUGRFrom;
            CurrentUGRFrom = ultraGrid1.Rows[m_nDelIndex];

            string strCreditCardNo = CurrentUGRFrom.Cells["信用证号"].Value.ToString();
            DateTime dtRecvMoneyDate = Convert.ToDateTime(CurrentUGRFrom.Cells["收款日"].Value.ToString());

            DataSet ds = m_bllCreditCardRegisterTab.GetList(" CreditCardNo = '" + strCreditCardNo + "' and RecvMoneyDate = '" + dtRecvMoneyDate + "'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                decimal dDhlFee = 0;
                decimal dNegotiatingFeel = 0;
                decimal dNotifyingFee = 0;
                decimal dModifyFee = 0;
                decimal dTelegraphFee = 0;
                for(int i = 0; i < ds.Tables[0].Rows.Count; ++i)
                {
                    string strNo = ds.Tables[0].Rows[i]["合同号"].ToString();
                    if (strNo.Length > 0)
                    {
                        if (strContractNo.Length > 0)
                            strContractNo.Append("/");

                        strContractNo.Append(strNo);
                    }

                    dDueTableFee += Convert.ToDecimal(ds.Tables[0].Rows[i]["交单金额"].ToString());
                    dForeignlFee += Convert.ToDecimal(ds.Tables[0].Rows[i]["国外扣费"].ToString());
                    if (i == 0)
                    {
                        dDhlFee += CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[i]["应收快递费"].ToString()) / 100, 0);
                        dNegotiatingFeel += CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[i]["应收议付费"].ToString()) / 100, 0);
                        dNotifyingFee += CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[i]["应收通知费"].ToString()) / 100, 0);
                        dModifyFee += CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[i]["应收修改费"].ToString()) / 100, 0);
                        dTelegraphFee += CommonCompute.ChinaRound(Convert.ToDecimal(ds.Tables[0].Rows[i]["应收电报费"].ToString()) / 100, 0);
                    }
                }

                 int nIndex = 1;
                DataRow dr = dtNew.NewRow();
                dr["序号"] = nIndex.ToString();
                dr["项目"] = "应收快递费";
                dr["金额（RMB）"] = dDhlFee.ToString();
                dr["备注"] = "";
                dtNew.Rows.Add(dr.ItemArray);

                nIndex++;
                dr = dtNew.NewRow();
                dr["序号"] = nIndex.ToString();
                dr["项目"] = "应收议付费";
                dr["金额（RMB）"] = dNegotiatingFeel.ToString();
                dr["备注"] = "";
                dtNew.Rows.Add(dr.ItemArray);

                nIndex++;
                dr = dtNew.NewRow();
                dr["序号"] = nIndex.ToString();
                dr["项目"] = "应收通知费";
                dr["金额（RMB）"] = dNotifyingFee.ToString();
                dr["备注"] = "";
                dtNew.Rows.Add(dr.ItemArray);

                nIndex++;
                dr = dtNew.NewRow();
                dr["序号"] = nIndex.ToString();
                dr["项目"] = "应收修改费";
                dr["金额（RMB）"] = dModifyFee.ToString();
                dr["备注"] = "";
                dtNew.Rows.Add(dr.ItemArray);

                nIndex++;
                dr = dtNew.NewRow();
                dr["序号"] = nIndex.ToString();
                dr["项目"] = "应收电报费";
                dr["金额（RMB）"] = dTelegraphFee.ToString();
                dr["备注"] = "";

                dtNew.Rows.Add(dr.ItemArray);
            }

            return strContractNo.ToString();
        }


        private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
        {
            ultraGrid1.DisplayLayout.Override.CellAppearance.TextHAlign = HAlign.Center;
            ultraGrid1.DisplayLayout.Override.CellAppearance.TextVAlign = VAlign.Middle;
            ultraGrid1.DisplayLayout.Override.MergedCellAppearance.TextHAlign = HAlign.Center;
            ultraGrid1.DisplayLayout.Override.MergedCellAppearance.TextVAlign = VAlign.Middle;

                        
            ultraGrid1.DisplayLayout.Bands[0].Columns["实收款"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["实收款"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);
                        
            ultraGrid1.DisplayLayout.Bands[0].Columns["外汇牌价"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["外汇牌价"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);

            ultraGrid1.DisplayLayout.Bands[0].Columns["国外扣费"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["国外扣费"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);

            ultraGrid1.DisplayLayout.Bands[0].Columns["国外扣费明细"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["国外扣费明细"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);
                        
            ultraGrid1.DisplayLayout.Bands[0].Columns["国外扣费占比"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["国外扣费占比"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);
                        
            ultraGrid1.DisplayLayout.Bands[0].Columns["交单到收款天数"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["交单到收款天数"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);

            ultraGrid1.DisplayLayout.Bands[0].Columns["应收快递费"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收快递费"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);

                  ultraGrid1.DisplayLayout.Bands[0].Columns["应收议付费"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收议付费"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);
                        
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收通知费"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收通知费"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);
                        
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收修改费"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收修改费"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);

            ultraGrid1.DisplayLayout.Bands[0].Columns["应收电报费"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收电报费"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);

            ultraGrid1.DisplayLayout.Bands[0].Columns["应收合计"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收合计"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);
                        
            ultraGrid1.DisplayLayout.Bands[0].Columns["国内扣费占比"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["国内扣费占比"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);
                        
            ultraGrid1.DisplayLayout.Bands[0].Columns["扣费日"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["扣费日"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);

            ultraGrid1.DisplayLayout.Bands[0].Columns["应付快递费"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应付快递费"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);





            ultraGrid1.DisplayLayout.Bands[0].Columns["快递费扣费日"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["快递费扣费日"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);

            ultraGrid1.DisplayLayout.Bands[0].Columns["应付议付费"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应付议付费"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);

                  ultraGrid1.DisplayLayout.Bands[0].Columns["议付费扣费日"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["议付费扣费日"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);
                        
            ultraGrid1.DisplayLayout.Bands[0].Columns["应付通知费"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应付通知费"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);
                        
            ultraGrid1.DisplayLayout.Bands[0].Columns["通知费扣费日"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["通知费扣费日"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);

            ultraGrid1.DisplayLayout.Bands[0].Columns["应付电报费"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应付电报费"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);

            ultraGrid1.DisplayLayout.Bands[0].Columns["电报费扣费日"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["电报费扣费日"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);
                        
            ultraGrid1.DisplayLayout.Bands[0].Columns["应付合计"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应付合计"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);
                        
            ultraGrid1.DisplayLayout.Bands[0].Columns["业务编号"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["业务编号"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);

            ultraGrid1.DisplayLayout.Bands[0].Columns["发票号"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["发票号"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);


        }
        /*
        private void ultraGridExcelExporter1_BeginExport(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.BeginExportEventArgs e)
        {
            UltraGridRow CurrentUGRFrom;
            CurrentUGRFrom = ultraGrid1.Rows[m_nDelIndex];

            Worksheet ws = e.CurrentWorksheet;

            ws.Rows[0].CellFormat.Font.Bold = ExcelDefaultableBoolean.True;
            ws.Rows[1].CellFormat.Font.Bold = ExcelDefaultableBoolean.True;
            ws.Rows[2].CellFormat.Font.Bold = ExcelDefaultableBoolean.True;
            ws.Rows[3].CellFormat.Font.Bold = ExcelDefaultableBoolean.True;
            ws.Rows[4].CellFormat.Font.Bold = ExcelDefaultableBoolean.True;
            ws.Rows[5].CellFormat.Font.Bold = ExcelDefaultableBoolean.True;
            ws.Rows[6].CellFormat.Font.Bold = ExcelDefaultableBoolean.True;
            ws.Rows[7].CellFormat.Font.Bold = ExcelDefaultableBoolean.True;
            ws.Rows[8].CellFormat.Font.Bold = ExcelDefaultableBoolean.True;

            ws.Rows[0].Cells[0].CellFormat.Font.Height = 300;
            ws.Rows[0].Cells[0].Value = @"客户：" + CurrentUGRFrom.Cells["工厂名称"].Text.ToString();
            ws.Rows[0].Cells[4].Value = @"业务员：" + CurrentUGRFrom.Cells["跟单业务"].Text.ToString();
            ws.Rows[1].Cells[0].Value = @"业务编号:" + CurrentUGRFrom.Cells["议付银行"].Text.ToString() + CurrentUGRFrom.Cells["业务编号"].Value.ToString();
            ws.Rows[2].Cells[0].Value = @"信用证号：" + CurrentUGRFrom.Cells["信用证号"].Value.ToString();
            ws.Rows[3].Cells[0].Value = @"发票号:" + CurrentUGRFrom.Cells["发票号"].Value.ToString();
            ws.Rows[4].Cells[0].Value = @"合同号：" + CurrentUGRFrom.Cells["合同号"].Value.ToString();
            decimal dJDValue = Convert.ToDecimal(CurrentUGRFrom.Cells["交单金额"].Value.ToString()) - Convert.ToDecimal(CurrentUGRFrom.Cells["国外扣费"].Value.ToString());
            ws.Rows[5].Cells[0].Value = @"交单金额:USD：" + CurrentUGRFrom.Cells["交单金额"].Value.ToString() + "-" + CurrentUGRFrom.Cells["国外扣费"].Value.ToString() + "=" + dJDValue.ToString();
            ws.Rows[5].Cells[4].Value = @"(到帐日:" + CurrentUGRFrom.Cells["收款日"].Text.ToString() + ",汇率:" + CurrentUGRFrom.Cells["外汇牌价"].Value.ToString() + ")";
            ws.Rows[7].Cells[0].Value = @"收费项目（" + CurrentUGRFrom.Cells["快递费扣费日"].Text.ToString() + "):";

            e.CurrentRowIndex = 9;
            e.CurrentColumnIndex = 1;
            ws.PrintOptions.Orientation = Infragistics.Excel.Orientation.Landscape;//打印横向
            ws.PrintOptions.BottomMargin = 0.2;
            ws.PrintOptions.TopMargin = 0.2;
            ws.PrintOptions.LeftMargin = 0.2;
            ws.PrintOptions.RightMargin = 0.2; 
        }

        private void ultraGridExcelExporter1_RowExported(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.RowExportedEventArgs e)
        {
            e.CurrentColumnIndex = 1;
        }

        private void ultraGridExcelExporter1_HeaderRowExported(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.HeaderRowExportedEventArgs e)
        {
            e.CurrentColumnIndex = 1;
        }
        */
    }
}
